<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../common/header.jsp" %>
<style>
    body {
        background-color: #f0f0f0;
    }
</style>
    <div class="row">
        <div class="col-sm-12">

            <div style="width: 100%; position: relative; background: #ffffff; border: 1px solid #cccccc; margin: 80px 0; padding: 40px 15px;">
                <div class="log-icon"></div>
                <h2 class="text-center" style="line-height: 60px; font-size: 24px;">Accounting Change Readiness <div class="log-icon icon-right"></div></h2>

                <div class="row">
                    <div class="col-lg-10 col-md-offset-1 mt10 question" id="question-js">
                        <p>To assess the impact of the implementation of new IFRSs on your organization.</p>
                        <div id="confirm-js">

                        </div>
                        <button id="next-js" style="" type="button" class="btn btn-primary btn-lg center-block pull-left">
                            submit
                        </button>
                        <a href="javascript:history.go(-1)" style="width: 150px; margin-left: 30px" type="button" class="btn btn-default  btn-lg center-block pull-left">
                            previous
                        </a>

                    </div>
                </div>

            </div>
        </div>

    </div>

<%@ include file="../common/footer.jsp" %>

<script>
    $(function(){
        var object = [], data= {};

        var answer = $.parseJSON(window.localStorage.getItem('questionAnswerData'));

        var questionTitle =  $.parseJSON(window.localStorage.getItem('questionTitleData'));
        //console.log(answer);
        //console.log(questionTitle);
        $.get('html/answerConfirm/confirm.html',function(html){
            var tml =_.template(html);
            $('#confirm-js').html(tml({answer:answer, questionTitle:questionTitle}));
            $('#next-js').click(function(){
                var data = answer;
                data.results = results();   //得到结果
                $.ajax({
                    url:'/questionnaire/answer/addItemPost',
                    type:'post',
                    dataType:'json',
                    data:data,
                    success:function(dataSucc){
                        window.localStorage.setItem('answerResults',data.results);
                       //window.location.href='/questionnaire/results';
                    }
                });
            });
        });

//        算出结果
        function results(){
            var resArr = answer.content.split(',');
            var highArr = [];
            var score = 0;
            var results = [];//'Low';

            $.each(resArr,function(i,item){
                if(item == 'true'){   //客户回答yes
                    score++            //分数
                    if(questionTitle[i].impact == 'High'){
                        highArr.push(questionTitle[i].id);
                    }
                }
            });

            if(parseInt(highArr.length)>=4){
                results = 'High';
            }else if(3 >=highArr.length && highArr>=1){
                results = 'Moderate';
            }else{
                results = 'Low';
            }

            return results;
        }

    });

</script>